#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author： 胡浩浩
# datetime： 2021/12/28 15:45 
# ide： PyCharm
from sqlalchemy.orm import Session
from Models.caseModel import case_model
from Schemas.caseSchema import case_schema


def get_case_by_id(db: Session, case_id: int):
    return db.query(case_model.Case).filter(case_model.Case.id == case_id).first()


def get_case_list(db: Session, skip: int = 0, limit: int = 10):
    return db.query(case_model.Case).offset(skip).limit(limit).all()


def create_case(db: Session, case: case_schema.CaseCreate):
    db_case = case_model.Case(**case.dict())
    db.add(db_case)
    db.commit()
    db.refresh(db_case)
    return db_case
